<?php
	session_start();
	require_once("../db_connect.php");

	//管理者ログイン処理

	$login_id  = htmlspecialchars($_POST['login_id'],ENT_QUOTES,"UTF-8");
	$password   = htmlspecialchars($_POST['pass'],ENT_QUOTES,"UTF-8");
	$manager_name = "";
	$manager_pass = "";

	if(array_key_exists("user_name",$_SESSION)?true:false){
		$_SESSION = array();
	}

	$sql = "SELECT family_name,given_name,manager_id,password
			FROM manager
			WHERE login_id = ?
			LIMIT 0 , 30";

	$res =& $db->query($sql,$login_id);
	if (PEAR::isError($res)) {
	    die($res->getMessage());
	}

	while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {
	    $manager_name = $row['family_name'].$row['given_name'];
	    $manager_id = $row['manager_id'];
	    $manager_pass = $row['password'];
	}

	if (PEAR::isError($res)) {			//SQLの実行に失敗すればここでエラー文を出力
		die($res->getMessage("aho"));
	}

	if($manager_id){
		if($password == $manager_pass){
			$_SESSION["manager_name"] = $manager_name;
			$_SESSION["manager_id"] = $manager_id;
			header("Location: ../../manager_index.php");
		}else{
			$_SESSION["error"] = "パスワードが間違っています。";
			header("Location: manager_login.php");
		}
	}else{
		$_SESSION["error"] = "ユーザ名が間違っています。";
		header("Location: manager_login.php");
	}

?>